import {AsyncThunk} from "@reduxjs/toolkit";
import React from "react";
import {App, Form, Spin} from "antd";
import {useAppDispatch} from "../../redux/hook";

// interface ListProps<T> {
//     items: T[];
//     renderItem: (item: T) => React.ReactNode;
// }

interface ListProps<T> {
    /**
     * 添加数据的redux异步action
     */
    fetchAddData: AsyncThunk<T, number, any> ,
    /**
     * 表单数据的初始值
     */
    initialValues?: T ,
    children: React.ReactNode ;
}

function List<T>(props: ListProps<T>) {

    const { message } = App.useApp();
    const [form] = Form.useForm<T>() ;


    const dispatch = useAppDispatch() ;
    const [loading, setLoading] = React.useState<boolean>(false) ;


  const onFinish = async (value: T) => {
      const res = await dispatch(props.fetchAddData(1300000001)).unwrap().then( (res:any) => res) ;
  } ;

    return (
        <Spin
            spinning={loading}
            tip={"正在提交数据..."}
            delay={500}
        >
            <Form<T>
                form={form}
                onFinish={onFinish}
            >


            </Form>
        </Spin>
    );
}